import { AfterViewInit, Component, ElementRef, OnInit } from '@angular/core';

import { CommonService } from '../../services/common.service';
import { HttpRequestService } from '../../services/http-request.service';

@Component({
    selector: 'op-sidebar',
    templateUrl: './sidebar.component.html'
})
export class SidebarComponent implements OnInit, AfterViewInit {
    menuItems: any[] = [];

    constructor(
        private commonService: CommonService,
        private elementRef: ElementRef,
        private httpRequestService: HttpRequestService
    ) { }

    ngOnInit(): void {
        this.httpRequestService.getWithoutBaseUrl<any[]>('assets/demo-data/side-menu.json').subscribe(data => this.menuItems = data);
    }

    ngAfterViewInit(): void {
        // this.viewInitCompleted.emit(true);

        this.commonService.appendScriptChildToElement(this.elementRef, [
            'js/sidebarmenu.js',
            'js/custom-sidebar.js'
        ]);
    }
}